﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    class DbHelper
    {
        //数据库链接

        private static readonly string connectionString = "server = .;database=Blogs;uid=sa;pwd=qaz888838";

        //添加和修改数据数据
        public static int Operate(string sql)
        {

                SqlConnection sqlConnection = new SqlConnection(connectionString);

                SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);

                sqlConnection.Open();

                return sqlCommand.ExecuteNonQuery();

            
        }

        internal static DataTable Table(string sql)
        {
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, connectionString);

            DataTable dataTable = new DataTable();

            sqlDataAdapter.Fill(dataTable);

            return dataTable;
        }

        //判断查询的结果有几条
        public static int Operate1(string sql)
        {
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, connectionString);

            DataSet dataSet = new DataSet();

            return sqlDataAdapter.Fill(dataSet);
        }
    }
}
